#ifndef EVENT_EVENTLOOPTHREAD_H_
#define EVENT_EVENTLOOPTHREAD_H_

#include <fermat/common/noncopyable.h>
#include <fermat/common/mutex.h>
#include <fermat/common/cond.h>
#include <fermat/common/thread.h>
#include <fermat/event/event_loop.h>
#include <functional>
#include <string>
#include <memory>

namespace fermat {
namespace event {

class EventLoopThread : public fermat::noncopyable {
public:
    typedef std::function<void(EventLoopPtr)> ThreadInitCallback;

    EventLoopThread(const ThreadInitCallback& cb = ThreadInitCallback(),
                            const std::string &name = std::string());
    ~EventLoopThread();
    EventLoopPtr start();
    EventLoopPtr getLoop() { return _loop; }
    void stop();
    

private:
    void threadFunc();
private:
    EventLoopPtr                      _loop;
    bool                              _exiting;
    fermat::Mutex                     _mutex;
    fermat::Cond                      _cond;
    fermat::Thread                    _thread;
    ThreadInitCallback                _callback;
};

typedef std::shared_ptr<EventLoopThread> EventLoopThreadPtr;
}
}
#endif